package cn.lee.test.controller;

import cn.lee.test.common.dataFormat.RequestResult;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;


/**
 * @author : lichl(李承霖)
 * create: 2022/2/23 20:10 周三
 */

@RestController
@RequestMapping("/pay")
@Api(tags = {"支付测试接口"})
public class PayTestController{
  
  
  @PostMapping("/callback")
  @ApiOperation("回调地址测试")
  public RequestResult<Map<String, Object>> creatUser(@RequestParam(required = false) Map<String, Object> body) throws IOException{
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM-HH-mm-ss");
    String nowDate = dateFormat.format(new Date());
    String path = ResourceUtils.getURL("classpath:").getPath() + "static/upload/";
    path = path.substring(1);
    String realPath = path.replace('/', '\\');
    File file = new File(realPath);
    if(!file.exists()){
      file.mkdirs();
    }
    String fileName = "/"+nowDate+".json";
    FileOutputStream outputStream = new FileOutputStream(new File(realPath + fileName));
    String josnString = JSON.toJSONString(body);
    outputStream.write(josnString.getBytes());
    outputStream.close();
    System.out.printf("时间:" + nowDate + ";====我接收到了回调!====");
    return new RequestResult<>("200", "success", body);
  }
  
}
